#ifndef DV_FRAME_QUEUE_H
#define DV_FRAME_QUEUE_H
#include <Locks.h>
#include <Socket.h>
using namespace kascale;
#include <BasicTypes.h>

#include <list>
#include <vector>
using namespace std;

class DVPacket
{
public:
	u_int32_t	ref_count;
	char*		pdata;
	u_int32_t	length;
	IPEndPoint	srcep;
public:
	DVPacket()
	{
		ref_count = 0;
		pdata = NULL;
		length = 0;
	}
	DVPacket(const DVPacket& pkt)
	{
		this->operator =(pkt);
	}
	DVPacket& operator=(const DVPacket& pkt)
	{
		if(this == &pkt)
			return *this;
		ref_count = pkt.ref_count;
		pdata = pkt.pdata;
		length = pkt.length;
		srcep = pkt.srcep;
		return *this;
	}
};

typedef list<DVPacket>::iterator packet_iterator;

class DVPacketQueue
{
public:
	DVPacketQueue();
	~DVPacketQueue();
	bool Init();
	bool Cleanup();
	bool AddPacket(DVPacket pkt);
	packet_iterator GetFirstPacket();
	char* GetNextPacket(packet_iterator& it, u_int32_t& length, IPEndPoint& ep, u_int32_t& pkt_left);
	bool ReleaseIterator(packet_iterator it);
	u_int32_t GetPacketCount();
	void GetFreePacket(DVPacket& pkt);
private:
	list<DVPacket>	packets;
	int32_t			packet_count;
	SimpleLock		pkt_lock;
	vector<DVPacket>	free_packets;
	SimpleLock		free_pkt_lock;
};


#endif // !defined DV_FRAME_QUEUE_H

